<template>
  <el-popover
    :open-delay="1500"
    placement="bottom"
    trigger="hover"
    :title="'文件名：' + file.name"
  >
    <div
      slot="reference"
      class="file"
      v-on:dblclick="clickFunc(file)"
      @contextmenu.stop="rightClick($event, file)"
    >
      <i class="icon" :class="fileType[file['typeId']].typeSuffix"></i>
      <span>{{ file.name }}</span>
    </div>
    <div class="popover-content">
      <div>
        <span>文件类型：{{ fileType[file["typeId"]]["typeDesc"] }}</span>
      </div>
      <div>
        <span>创建日期：{{ file["createTime"] }}</span>
      </div>
      <div>
        <span>更新日期：{{ file["updateTime"] }}</span>
      </div>
      <div
        v-show="
          fileType[file['typeId']]['typeSuffix'] !== 'dir' && file.size != null
        "
      >
        <span
          >文件大小：{{ (file.size / Math.pow(1024, 2)).toFixed(2) }} M</span
        >
      </div>
      <div v-show="file.status === 0">
        <span>保留剩余天数：{{ getLeftDays(file["updateTime"]) }} </span>
      </div>
    </div>
  </el-popover>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  name: "fileIcon",
  computed: { ...mapGetters(["fileType"]) },
  props: {
    clickFunc: {
      type: Function,
      default: () => {}
    },
    rightClick: {
      type: Function,
      default: () => {}
    },
    file: null
  },
  methods: {
    getLeftDays(updateTime) {
      let exprDate = new Date(updateTime);
      exprDate = exprDate.getTime() + 1000 * 60 * 60 * 24 * 15;
      return Math.floor(
        (exprDate - new Date().getTime()) / (1000 * 60 * 60 * 24)
      );
    }
  }
};
</script>

<style lang="less" scoped>
.file:hover {
  background-color: #eaeaff;
}
.file {
  width: 80px;
  height: 80px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: keep-all;
  margin: 10px;
  .icon {
    margin: 0 auto;
    display: block;
    width: 55px;
    height: 55px;
    background: no-repeat 100% 100%;
    background-size: cover;
  }

  .dir {
    background-image: url("../../static/icons/folder.png");
  }
  .zip {
    background-image: url("../../static/icons/zip.png");
  }
  .misc {
    background-image: url("../../static/icons/misc.png");
  }
  .mp3 {
    background-image: url("../../static/icons/music.png");
  }
  .jpg {
    background-image: url("../../static/icons/jpg.png");
  }
  .mp4 {
    background-image: url("../../static/icons/video.png");
  }
  .txt {
    background-image: url("../../static/icons/txt.svg");
  }
  span {
    font-size: 12px;
  }
}
</style>
